#include "logindialog.h"
#include "ui_logindialog.h"

LoginDialog::LoginDialog(QWidget *parent,mode m) :
    QDialog(parent),
    ui(new Ui::LoginDialog)
{
    ui->setupUi(this);
    this->setWindowTitle("登录");

    //设置当前标签页
    ui->tabWidget->setCurrentIndex(m);

    //重置按钮实现
    connect(ui->pushButton_doctorReset,&QPushButton::clicked,[=]{
        ui->lineEdit_doctorAccount->setText("");
        ui->lineEdit_doctorPassword->setText("");
    });
    connect(ui->pushButton_patientReset,&QPushButton::clicked,[=]{
        ui->lineEdit_patientAccount->setText("");
        ui->lineEdit_patientPassword->setText("");
    });
}

LoginDialog::~LoginDialog()
{
    delete ui;
}

void LoginDialog::setCurrentPage(mode m)
{
    ui->tabWidget->setCurrentIndex(m);
}

void LoginDialog::keyPressEvent(QKeyEvent *ev)
{
    //设置回车键自动登录
    switch (ev->key()) {
    case Qt::Key_Return:
    case Qt::Key_Enter:
        if(ui->tabWidget->currentIndex())
            on_pushButton_doctorLogin_clicked();
        else
            on_pushButton_patientLogin_clicked();
        break;
    default:
        break;
    }
}

void LoginDialog::on_pushButton_patientLogin_clicked()
{
    //患者登录
    bool success=1;
    if(success){
        emit patientLoginSuccess();
        this->close();
    }
}

void LoginDialog::on_pushButton_doctorLogin_clicked()
{
    //医生登录
    bool success=1;
    if(success){
        emit doctorLoginSuccess();
        this->close();
    }
}
